package net.stratusprogramming.school.Game;

import net.stratusprogramming.school.Game.Combatants.MainCharacter;
import net.stratusprogramming.school.Game.Framework.Screen;
import net.stratusprogramming.school.Game.Framework.Battle.HumanCombatant;
import net.stratusprogramming.school.Game.Framework.GUI.Fonts;
import net.stratusprogramming.school.Game.Framework.System.Config;
import net.stratusprogramming.school.Game.Framework.System.InstanceMgr;
import net.stratusprogramming.school.Game.Framework.System.Logger;
import net.stratusprogramming.school.Game.Framework.System.SaveMgr;
import net.stratusprogramming.school.Game.Screens.IntroScreen;
import net.stratusprogramming.school.Game.World.World;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;


public class Main extends BasicGame {
	
	private Screen mainScreen;
	
	public Main(String title) {
		super(title);
		Logger.startLogger();
		Logger.logln("System", "Working version 1");
		InstanceMgr.main = this;

	}

	public static void main(String[] argv) {  
		try {
			AppGameContainer container = new AppGameContainer(new Main("Purple Hayes"));
			InstanceMgr.container = container;
			container.setIcons(new String[] {"res/images/ico32.png", "res/images/ico16.png"});
			container.setTargetFrameRate(Config.FPS);
			container.setShowFPS(false);
			container.setDisplayMode(Config.WINDOW_WIDTH, Config.WINDOW_HEIGHT, false);
			container.setVerbose(true);
			container.start();
		} catch (SlickException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void init(GameContainer container) throws SlickException {
		Logger.logln("System", "Container open");
		InstanceMgr.input = container.getInput();		
		InstanceMgr.player = new MainCharacter();
		
		// load stuff here
		Fonts.loadFonts();
		
		mainScreen = InstanceMgr.world = new World();			
		SaveMgr saveMgr = InstanceMgr.saveMgr = new SaveMgr();
		saveMgr.loadSave();
		mainScreen = new IntroScreen();
	}
	
	@Override
	public void render(GameContainer container, Graphics g) throws SlickException {
		mainScreen.render(g);
	}	

	@Override
	public void update(GameContainer container, int delta) throws SlickException {
		mainScreen.update(delta);
	}
	
	public void setScreen(Screen screen) {
		mainScreen = screen;
	}
}
